﻿using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Score
{
    public partial class Score_BrushIDCard_Form : BaseForm
    {
        ServiceComm serviceComm = new ServiceComm();
        public Score_BrushIDCard_Form()
        {
            InitializeComponent();
            userControl_ReadIdCard1.Button_Click_Event += btnScan_Click;
            userControl_ReadIdCard1.TextEnabled = true;
        }
        private void CheckAppointmentStudents(string strIdCard)
        {
            bool result = false;
            TB_Sys_SystemInfo model = serviceComm.GetSystemInfoModel(ConstSystem.SystemIdCard);
            if (model != null)
            {
                string strValue = model.SystemInfoName;
                if (!string.IsNullOrEmpty(strValue))
                {
                    string[] strSZ = strValue.Split(',');
                    foreach (string str in strSZ)
                    {
                        if (str == strIdCard)
                        {
                            result = true;
                            break;
                        }
                    }
                }
            }
            if (result == false)
            {
                using (DataTable dt = new ServiceBase().GetExaminerTable(strIdCard, string.Empty, string.Empty, string.Empty, string.Empty))
                {
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        if (dt.Rows[0]["SpecialityKindsNO"].ToSafeString() == SessionerHelper.SpecialityKindsNO)
                        {
                            result = true;
                        }
                    }
                }
            }
            if (result)
            {
                this.Close();
                Score_ScoreUpForm_List upForm = new Score_ScoreUpForm_List();
                upForm.ShowDialog();
            }
            else
            {
                DevHelper.ShowErrorMessageBox("该身份证号没有权限,无法进行上报!");
            }
        }

        private void btnScan_Click(object sender, EventArgs e)
        {
            userControl_ReadIdCard1.ReadCard();
            if (userControl_ReadIdCard1.TextValue.Length > 0)
            {
                CheckAppointmentStudents(userControl_ReadIdCard1.TextValue);
            }
        }
    }
}
